Product : ISaGRAF V3.3
Date : 24-November-1998
File : Checksum.htm
Subject : Checksums embedded with ISaGRAF TIC code
Keywords: Checksum - TIC
____________________________________________________________________
ISaGRAF Workbench version 3.3 embeds in downloaded code a
list of checksums calculated on programs.
There is one checksum for each program.
A new table in the downloaded code gives the list of
checksums.
The new table is called __PROGCRC.
It is generated only if the target version is higher or
equal to 2.00.
That is the version number attached to the target and
entered in .RSC file.
Below is an example of new .RSC file header:
* resource identification (version 2.00: checksums embedded)
Name=ISA86M
Version=2.00
Comment=TIC code for Intel
If version number is 1.xx, checksums are not embedded,
i.e. the downloaded code is not changed from 3.2 version.
When checksums are embedded, the main pointer to __PROGCRC
table is put at the end of the main header structure, at
the beginning of the downloaded code:
00000000: __MAIN
00000000: 01 00 00 00 * High/Low flag
00000004: 68 00 00 00 * defprod
00000008: 44 00 00 00 * defappli
0000000C: D4 05 00 00 * defusf
00000010: D8 05 00 00 * deffbl
00000014: 80 00 00 00 * deffcnv
00000018: 84 00 00 00 * deftcnv
0000001C: 1C 07 00 00 * defvar
00000020: 14 04 00 00 * codevar
00000024: 88 00 00 00 * defoem
00000028: 90 00 00 00 * codeoem
0000002C: 74 05 00 00 * defhie
00000030: 98 05 00 00 * defprog
00000034: AC 05 00 00 * codeprog
00000038: C0 05 00 00 * linksfc
0000003C: DC 11 00 00 * resources
00000040: 7C 11 00 00 * <<<< THIS IS THE OFFSET OF __PROCRC TABLE
When checksums are embedded, the __PROGCRC table is put after
other tables, before resources.
Resources still are at the very end of the file:
... ISaGRAF tables and TIC code ...
0000117C: __PROGCRC
0000117C: 01 00 00 00 C4 07 00 00 - D0 00 00 00 25 E9 F2 5B
0000118C: 02 00 00 00 70 09 00 00 - 54 01 00 00 F8 71 DA 5A
0000119C: 03 00 00 00 B0 0B 00 00 - FC 01 00 00 B2 D1 AE 40
000011AC: 04 00 00 00 08 0E 00 00 - 10 01 00 00 05 DD 4E 4C
000011BC: 05 00 00 00 5C 0F 00 00 - 20 02 00 00 27 47 67 C5
000011CC: 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00
000011DC: __RESOURCE
000011DC: 00 00 00 00
000011E0: __CODECRC
000011E0: A6 F4 DB 09
000011E4: FB 90 3B BF
Note that two other checksums, calculated on the entire
file (including resources and other checksums) are put
at the end of the code.
The first one includes all the files except code generation
date/time stamp and application code version number.
Thus, this checksum is stable from one compiling to another,
if the application is not changed.
The second one includes data/time stamp plus code version
number, and can change even if the application is modified.
This checksum was already available on ISaGRAF V3.23.
Below is the format of __PROGCRC table:
_PROGCRC = <prog_def> .... <prog_def> <end_mark>
<prog_def> = <prog_num> <prog_off> <prog_siz> <prog_crc>
<prog_num> = 32 bit integer = internal program number
(from 1 to N)
<prog_off> = 32 bit integer = offset of program code from
beginning of file
<prog_siz> = 32 bit integer = size (in bytes) of program code
<prog_crc> = 32 bit integer = program checksum
<end_mark> = 16 null characters
Checksum calculation:
All checksums are calculated according to the same algorithm.
Checksum initial value is 0xffffffff.
Then the 'addbyte' function is sequentially called for each
character:
static uint32 CHEKSUM;
void checksum_init (void)
{
CHECKSUM = 0xffffffff;
}
void checksum_addbyte (uchar cbyte)
{
uchar i;
uint32 mem1;
CHECKSUM ^= (uint32)cbyte;
for (i=1; i<= 8; i++) {
mem1 = CHECKSUM;
CHECKSUM /= 2;
if (mem1 & 1) CHECKSUM ^= 0xA000A001;
}
}
____________________________________________________________________
Copyright © 1996-2009 ICS Triplex ISaGRAF Inc. All rights reserved.